package com.heima.kafka.controller;

import com.alibaba.fastjson.JSON;
import com.heima.kafka.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description: test
 * @Create by: JJ菜菜
 * @Date: 2022/1/10 11:36
 */
@RestController
public class HelloController {

    @Autowired
    private KafkaTemplate<String, String> kafkaTemplate;

    @GetMapping("/hello")
    public String hellow(){
        // 传递消息为对象
        User user = new User("张三", "21");
        String jsonString = JSON.toJSONString(user);
        kafkaTemplate.send("itcast-topic", jsonString);
        return "success";
    }
}


